<include file="__PUBLIC__/header"/>
<article class="page-container">
    <form action="{|U:'writeGroup'}" method="post" class="form form-horizontal" id="form">
        <input type="hidden" name="id" value="{$this_group.id}" />
        <div class="row cl">
            <div class="formControls col-xs-8 col-sm-12">
                <list from="$node_list" name="$node">
                    <dl class="permission-list">
                        <dt>
                            <label>
                                <input type="checkbox" name="rules[]" value="<?php echo $main_rules[$node['url']];?>" id="user-Character-<?php echo $main_rules[$node['url']];?>" class="auth_rules"/>{$node.title}</label>
                        </dt>
                        <dd>
                            <if value="isset($node['children'])">
                                <list from="$node['children']" name="$child">
                                    <dl class="cl permission-list2">
                                        <dt>
                                            <label>
                                                <input type="checkbox" value="<?php echo $child_rules[$child['url']];?>" name="rules[]" id="user-Character-<?php echo $child_rules[$child['url']];?>" class="auth_rules"/>{$child.title}</label>
                                        </dt>
                                        <if value="isset($child['operator'])">
                                            <list from="$child['operator']" name="$childs">
                                                <dd>
                                                    <label>
                                                        <input type="checkbox" value="<?php echo $child_rules[$childs['url']];?>" name="rules[]" id="user-Character-<?php echo $child_rules[$childs['url']];?>" class="auth_rules"/>{$childs.title}</label>
                                                </dd>
                                            </list>
                                        </if>
                                    </dl>
                                </list>
                            </if>
                        </dd>
                    </dl>
                </list>
            </div>
        </div>
        <div class="row cl text-r">
            <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
                <button type="submit" class="btn btn-primary radius"><i class="iconfont icon-duigou1"></i> 提交</button>
                <button type="button" class="btn btn-default radius" onClick="layer_close();">&nbsp;&nbsp;取消&nbsp;&nbsp;</button>
            </div>
        </div>
    </form>
</article>
<include file="__PUBLIC__/footer"/>
<script type="text/javascript">
    $(function () {
        var rules = [{$this_group['rules']}];
        $('.auth_rules').each(function(){
            if( $.inArray( parseInt(this.value,10),rules )>-1 ){
                $(this).prop('checked',true);
            }
        });

        $(".permission-list dt input:checkbox").click(function () {
            $(this).closest("dl").find("dd input:checkbox").prop("checked", $(this).prop("checked"));
        });
        $(".permission-list2 dd input:checkbox").click(function () {
            var l = $(this).parent().parent().find("input:checked").length;
            var l2 = $(this).parents(".permission-list").find(".permission-list2 dd").find("input:checked").length;
            if ($(this).prop("checked")) {
                $(this).closest("dl").find("dt input:checkbox").prop("checked", true);
                $(this).parents(".permission-list").find("dt").first().find("input:checkbox").prop("checked", true);
            }
            else {
                if (l == 0) {
                    $(this).closest("dl").find("dt input:checkbox").prop("checked", false);
                }
                if (l2 == 0) {
                    $(this).parents(".permission-list").find("dt").first().find("input:checkbox").prop("checked", false);
                }
            }
        });

        //表单提交
        $("#form").Validform({
            tiptype:2,
            ajaxPost:true,
            showAllError:true,
            callback:function(ret){
                ajax_progress(ret);
            }
        });
    });
</script>
</body>
</html>